package com.wufeng.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class ListDemo {
    public static void main(String[] args) {

        int[][] points = {{1,1},{3,4},{-1,0}};
        System.out.println(minTimeToVisitAllPoints(points));

    }

    public static int[] createTargetArray(int[] nums, int[] index) {
        List<Integer> list = new LinkedList<>();
        for (int i = 0; i < index.length; i++) {
            list.add(index[i], nums[i]);
        }
        int[] target = new int[nums.length];
        for(int i = 0; i < nums.length; i++){
            target[i] = list.get(i);
        }
        return target;
    }

    public int[] smallerNumbersThanCurrent(int[] nums) {
        int[] result = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            int count = 0;
            for (int j = 0; j < nums.length; j++) {
                if(nums[i] > nums[j]){
                    count ++;
                }
            }
            result[i] = count;
        }
        return result;
    }

    public int[] decompressRLElist(int[] nums) {
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < (nums.length / 2); i++) {
            for (int j = 0; j < nums[i * 2]; j++) {
                list.add(nums[i * 2 + 1]);
            }
        }
        return list.stream().mapToInt(i -> i).toArray();
    }

    public static int minTimeToVisitAllPoints(int[][] points) {
        int sum = 0;
        for (int i = 0; i < points.length - 1; i++){
            sum += Math.max(Math.abs(points[i+1][0] - points[i][0]),Math.abs(points[i+1][1] - points[i][1]));
        }
        return sum;
    }

}
